package com.bear.config;

import com.bear.bean.HelloProperties;
import com.bear.service.HelloService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LiuShanshan
 * @version V1.0
 * @Description
 */
@Configuration
@EnableConfigurationProperties(HelloProperties.class)  // 使用EnableConfigurationProperties可以使HelloProperties类里面的ConfigurationProperties起效果，拿到properties或者yml里面的配置
public class HelloServiceAutoConfiguration {
    private HelloProperties helloProperties;

    //通过构造方法注入配置属性对象HelloProperties
    public HelloServiceAutoConfiguration(HelloProperties helloProperties) {
        this.helloProperties = helloProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    public HelloService helloService(){
        return new HelloService(helloProperties.getName(), helloProperties.getAddress());
    }
}
